package com.study.demo.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitController {

    @Value("${loader.rabbitmq.exchange}")
    private String exchange;
    @Value("${loader.rabbitmq.routingKey}")
    private String routingKey;
    @Value("${loader.rabbitmq.queue}")
    private String queueName;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public void send() {
        String str = "hello world";
        rabbitTemplate.convertAndSend(exchange, routingKey, str);
        System.out.println("send success");
    }

    @GetMapping("/get")
    public void get() {
        Object object = rabbitTemplate.receiveAndConvert(queueName);
        System.out.println("get success:" + String.valueOf(object));
    }
}
